package com.xiaobao.coalproperty.module.user.view;

import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.xiaobao.coalproperty.R;
import com.xiaobao.coalproperty.other.base.BaseActivity;

import butterknife.BindView;

public class OrderPayActivity extends BaseActivity {

    @BindView(R.id.pay_wx)
    LinearLayout llWx;
    @BindView(R.id.pay_alipay)
    LinearLayout llAliPay;
    @BindView(R.id.pay_yinlian)
    LinearLayout llYinLian;
    @BindView(R.id.pay_iv_wx)
    ImageView ivWx;
    @BindView(R.id.pay_iv_alipay)
    ImageView ivAliPay;
    @BindView(R.id.pay_iv_yinlian)
    ImageView ivYinLian;
    @BindView(R.id.pay_price)
    TextView tvPrice;

    private ImageView[] mImageViews;
    private String oid;
    private double money;
    private int PAY_TYPE = -1;

    @Override
    protected int getContentView() {
        return R.layout.activity_order_pay;
    }

    @Override
    protected void init(Bundle savedInstanceState) {
        setLeftClickFinish();
        setTitle("支付");

        oid = getIntent().getStringExtra("oid");
        money = getIntent().getDoubleExtra("money", 0);

        tvPrice.setText(money + "");

        mImageViews = new ImageView[]{ivWx, ivAliPay, ivYinLian};

        llWx.setOnClickListener(mOnClickListener);
        llAliPay.setOnClickListener(mOnClickListener);
        llYinLian.setOnClickListener(mOnClickListener);

    }

    private View.OnClickListener mOnClickListener = new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            switch (v.getId()) {
                case R.id.pay_wx:
                    setLinearLayouBackground(0);
                    break;
                case R.id.pay_alipay:
                    setLinearLayouBackground(1);
                    break;
                case R.id.pay_yinlian:
                    setLinearLayouBackground(2);
                    break;
            }
        }
    };

    private void setLinearLayouBackground(int index) {
        PAY_TYPE = index;
        for (int i = 0; i < mImageViews.length; i++) {
            mImageViews[i].setImageDrawable(getResources().getDrawable(R.drawable.image_widget_pay_not_select));
            if (i == index) {
                mImageViews[i].setImageDrawable(getResources().getDrawable(R.drawable.image_widget_pay_select));
            }
        }
    }

    public void payClick(View view) {
        switch (PAY_TYPE) {
            case 0:
                showToast("正在调起微信支付");
                break;
            case 1:
                showToast("正在调起支付宝支付");
                break;
            case 2:
                showToast("正在调起银联支付");
                break;
            default:
                showToast("请选择支付方式");
                break;
        }

    }
}
